package com.rt.cloud.auth.controller.captchaImage;

import com.google.code.kaptcha.Producer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.awt.image.BufferedImage;

/**
 * 图片验证码生成接口
 *
 * @author CaiRui
 * @date 2018-12-10 12:07
 */
@Component("captchaGenerate")
public class ImageCaptchaGenerate implements CaptchaGenerate {

    @Resource
    private Producer producer;//config bean中配置

    @Override
    public ImageCaptchaVo generate() {
        String code = producer.createText();
        BufferedImage bufferedImage = producer.createImage(code);
        return new ImageCaptchaVo(bufferedImage, code, 60 * 5);//5分钟过期
    }
}
